
import 'package:flutter/material.dart';
import 'package:fl_chart/fl_chart.dart';

class RadarChartWidget extends StatefulWidget {
  const RadarChartWidget({super.key});

  @override
  State<RadarChartWidget> createState() => _RadarChartWidgetState();
}

class _RadarChartWidgetState extends State<RadarChartWidget> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('雷达图示例'),
      ),
      body: Center(
        child: AspectRatio(
          aspectRatio: 1.2,
          child: RadarChart(
            RadarChartData(
              radarTouchData: RadarTouchData(enabled: false),
              dataSets: getRadarDataSets(),
              radarBackgroundColor: Colors.white,
              borderData: FlBorderData(show: false),
              radarBorderData: BorderSide(color: Colors.grey),
              titleTextStyle: const TextStyle(
                color: Colors.black,
                fontSize: 14,
              ),
              tickBorderData: BorderSide(color: Colors.grey),
              ticksTextStyle: const TextStyle(
                color: Colors.grey,
                fontSize: 12,
              ),
              tickCount: 5,
            ),
          ),
        ),
      ),
    );
  }

  List<RadarDataSet> getRadarDataSets() {
    return [
      RadarDataSet(
        fillColor: Colors.blue.withOpacity(0.2),
        borderColor: Colors.blue,
        dataEntries: const [
          RadarEntry(value: 3),
          RadarEntry(value: 6),
          RadarEntry(value: 5),
          RadarEntry(value: 8),
          RadarEntry(value: 4),
        ],
        entryRadius: 3,
        borderWidth: 2,
      ),
    ];
  }
}
